'''
coding:utf-8
@Software:PyCharm
@Time:2022/8/11 11:43
@Author:liuyi
'''
import time

import IPy
from ping3 import ping
from multiprocessing import Process


ips = IPy.IP("192.168.2.0/24")
ips_lst = []
p_lst = []
num = 0
for ip in ips:
    num += 1
    if num == 1:
        continue
    ips_lst.append(str(ip))

def func(ip):
    test = ping(ip)
    if test:
        with open("ip.txt","a+") as f:
            f.write(ip + "\n")

if __name__ == '__main__':
    start = time.time()
    for i in ips_lst:
        p = Process(target=func,args=(i,))
        p_lst.append(p)
        p.start()
    for p in p_lst:
        p.join()
    end = time.time()
    print(end - start)

